package com.ht.impl.drawtool;

import com.mxgraph.util.mxPoint;

import javax.swing.*;
import java.awt.event.MouseEvent;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2010-6-17
 */
public class TextTool extends RectTool {

    public TextTool(String style) {
        super(style);
    }

    public void mouseClicked(MouseEvent e) {
        if (SwingUtilities.isLeftMouseButton(e)) {
            double factor = graphComponent.getGraph().getView().getScale();
            mxPoint offset = graphComponent.getGraph().getView().getTranslate();
            cell.getGeometry().setX((e.getX() - 40) / factor - offset.getX());
            cell.getGeometry().setY((e.getY() - 15) / factor - offset.getY());
            cell.getGeometry().setWidth(80);
            cell.getGeometry().setHeight(30);
            cell.setValue("Text Here");
            updateGraphElement();
        }
    }

    public void updateRect(MouseEvent e) {
        super.updateRect(e);
        cell.setValue("Text Here");
    }
}
